import { createRouter, createWebHashHistory } from "vue-router";
import IndexPage from "@/components/IndexPage.vue";
import SearchPage from "@/components/SearchPage.vue";
import userCenter from "@/components/UserCenter.vue";
import PostContent from "@/components/PostContent.vue";
import LoginPage from "@/components/LoginPage.vue";
import RegisterPage from "@/components/RegisterPage.vue";
import RegisterSuccess from "@/components/RegisterSuccess.vue";
import AddPostPage from "@/components/AddPostPage.vue";
import store from "@/store";
import WxLogin from "@/components/WxLogin.vue";
import MyPost from "@/components/MyPost.vue";
import MyComment from "@/components/MyComment.vue";
import ChangeInfo from "@/components/ChangeInfo.vue";
import MyAnonname from "@/components/MyAnonname.vue";
import UserAuth from "@/components/UserAuth.vue";
import CommunityNorms from "@/components/CommunityNorms.vue";
import UserAgreement from "@/components/UserAgreement.vue";
import ShareImg from "@/components/ShareImg.vue";
import forgetPasswordPage from "@/components/forgetPasswordPage.vue";
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/",
      component: IndexPage,
    },
    {
      path: "/search",
      component: SearchPage,
    },
    {
      path: "/putout",
      component: AddPostPage,
    },
    {
      path: "/user",
      component: userCenter,
    },
    {
      path: "/post",
      component: PostContent,
    },
    {
      path: "/login",
      component: LoginPage,
    },
    {
      path: "/register",
      component: RegisterPage,
    },
    {
      path: "/mypost",
      component: MyPost,
    },
    {
      path: "/mycomment",
      component: MyComment,
    },
    {
      path: "/changeinfo",
      component: ChangeInfo,
    },
    {
      path: "/myanonname",
      component: MyAnonname,
    },

    {
      path: "/authuser",
      component: UserAuth,
    },

    {
      path: "/ComNorms",
      component: CommunityNorms,
    },
    {
      path: "/useragree",
      component: UserAgreement,
    },
    {
      path: "/forgetpassword",
      component: forgetPasswordPage,
    },
  ],
});

// 全局前置守卫
// router.beforeEach((to, from, next) => {
//   // 在离开页面时保存滚动位置
//   if (from.path === "/") {
//     const scrollY = window.scrollY;
//     store.dispatch("saveScrollY", scrollY);
//   }
//   next();
// });

export default router;
